class ThreadClass1 implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 200; i++) {
            System.out.printf("%s-%d\n", Thread.currentThread().getName(), i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class ThreadClass2 extends Thread {
    public ThreadClass2(String name) {
        super(name);//给线程的名称赋值
    }
    // 子类型定义同名函数隐藏(覆盖)父类型的函数版本
    @Override
    public void run() {
        for (int i = 0; i < 200; i++) {
            System.out.printf("%s-%d\n", Thread.currentThread().getName(), i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class Test {
    public static void main(String[] args) {
        // 问题：当前程序运行时，有多少线程在工作？3个
        /*ThreadClass1 o1 = new ThreadClass1();
        ThreadClass1 o2= new ThreadClass1();
        Thread threadA = new Thread(o1, "threadA");
        Thread threadB = new Thread(o2, "threadB");
        threadA.start();
        threadB.start();*/
        ThreadClass2 threadA = new ThreadClass2("threadA");
        ThreadClass2 threadB = new ThreadClass2("threadB");
        threadA.start();
        threadB.start();
    }
}
